package uit.shoeshop.model;

import uit.shoeshop.dto.SlideshowDTO;
import uit.shoeshop.dao.SlideshowDAO;

import java.sql.SQLException;
import java.util.ArrayList;

public class SlideshowModel {
	public SlideshowModel(){
		
	}
	
	public ArrayList<SlideshowDTO> getAllEvent() throws SQLException{
		ArrayList<SlideshowDTO> slideshow = new ArrayList<SlideshowDTO>();

		SlideshowDAO tblSlideshow = new SlideshowDAO();
		
		/*
		 * Lay tat ca cac event
		 */
		slideshow = tblSlideshow.getSlideshow();
		
		tblSlideshow = null;
		return slideshow;
	}
	
	public SlideshowDTO getEventById(int sId) throws SQLException{
		SlideshowDTO slideshow;

		SlideshowDAO tblSlideshow = new SlideshowDAO();
		
		/*
		 * Lay tat ca cac event
		 */
		slideshow = tblSlideshow.getSlideshowById(sId);
		
		tblSlideshow = null;
		return slideshow;
	}	
	
	public int delSlideshow(int sId) throws SQLException{
		int result = 1;
		SlideshowDAO tblSlideshow = new SlideshowDAO();
		result = tblSlideshow.delSlideshow(sId);
		return result;
	}
	
	public int updateSlideshow(int sId,String title,String content,String image) throws SQLException{
		int result = 1;
		SlideshowDAO tblSlideshow = new SlideshowDAO();
		result = tblSlideshow.updateSlideshowById(sId, title, content, image);
		return result;		
	}
	
	public int insertSlideshow(String title,String content,String image) throws SQLException{
		int result = 1;
		ArrayList<SlideshowDTO> allEvent = this.getAllEvent();
		if(allEvent.size() > 5){
			result = 0;
		}else{
			SlideshowDAO tblSlideshow = new SlideshowDAO();
			result = tblSlideshow.insertSlideshow(title, content, image);
		}
		return result;		
	}	
}
